package com.dyz.swordFingerOffer;

public class GetUglyNumber_Solution49 {
    //数组保存所有2 3 5 的丑数
    public int GetUglyNumber_Solution(int index) {
        if (index == 0) {
            return 0;
        }
        int[] arr = new int[index];
        arr[0] = 1;
        int index1 = 0; //遍历丑数为2的队列
        int index2 = 0;//遍历丑数为3的队列
        int index3 = 0;//遍历丑数为5的队列

        for (int i = 1; i < index; i++) {
            arr[i] = Math.min(Math.min(arr[index1] * 2, arr[index2] * 3), arr[index3] * 5);
            if (arr[i] == arr[index1] * 2) {
                index1++;
            }
            if (arr[i] == arr[index2] * 3) {
                index2++;
            }
            if (arr[i] == arr[index3] * 5) {
                index3++;
            }
        }
        return arr[index - 1];
    }
}
